package edu.hawaii.server;

import org.junit.Test;

import junit.framework.TestCase;

/**
 * A test class for TimeLocationParse.
 * 
 * @author brandon lee
 */
public class TestTimeLocationParse extends TestCase {

  private TimeLocationParse tlp;
  
  /**
   * Sets up the test fixture. 
   * (Called before every test case method.) 
   */ 
  protected void setUp() { 
    tlp = new TimeLocationParse("MW 0900 to 1015 location POST 126 (Max Rm. capacity 54) (Instr: W Peterson)");
  } 


  /**
   * Tears down the test fixture. 
   * (Called after every test case method.) 
   */ 
  protected void tearDown() { 
    tlp = null;
  } 
  
  /**
   * Tests the set and get raw string. Test string has to be of proper length and "format".
   * 
   */
  @Test
  public void testSetGetRawString() {
  
    String rrtring = "fjdlka;";
    try{
      
      assertEquals("Checking set/get raw string", tlp.getRawString(), "MW 0900 to 1015 location POST 126 (Max Rm. capacity 54) (Instr: W Peterson)");
      
      tlp.setRawString(rrtring);
      assertNotSame("Checking set/get raw string", tlp.getRawString(), "fjdlka;");
      
      fail("string provided is too short and shouldn't pass");
    }
    catch(Exception e){
      
      System.out.println("Error caught exception: " + e);
      //should pass
    }
  }

  /**
   * Test if it spit up the raw string ok and if it stored the right location.
   */
  @Test
  public void testGetLocation() {
  
    assertEquals("Checking splitup and getLocation", tlp.getLocation(), "POST 126");
    
    tlp.setRawString("MW 0900 to 1015 location Keller 441323 (Max Rm. capacity 54) " 
                   + "(Instr: W Peterson)");
    assertEquals("Checking splitup and getLocation", tlp.getLocation(), "Keller 441323");
  }
  
  
  /**
   * Tests the spilit function and return function max room capacity.
   */
  @Test
  public void testGetMaxRoomCap() {
    
    assertEquals("Checking splitup and getLocation", tlp.getMaxRoomCap(), "54");
    
    tlp.setRawString("MW 0900 to 1015 location Keller 441323 (Max Rm. capacity 700) " 
                   + "(Instr: W Peterson)");
    assertEquals("Checking splitup and getLocation", tlp.getMaxRoomCap(), "700");
  }
  
  /**
   * Test the get split function and get Instructor.
   */
  @Test
  public void testGetInstructor() {
    
    assertEquals("Checking splitup and getInstructor", tlp.getInstructor(), "W Peterson");
    
    tlp.setRawString("MW 0900 to 1015 location Keller 441323 (Max Rm. capacity 700) " 
                   + "(Instr: W jackson)");
    assertEquals("Checking splitup and getLocation", tlp.getInstructor(), "W jackson");
  }

  /**
   * Test the get split function and get Instructor.
   */
  @Test
  public void testGetTime() {
    
    //System.out.println(tlp.getTime());
    assertEquals("Checking splitup and getLocation", tlp.getTime(), "900 am-1015 am");
    
    tlp.setRawString("MW 1200 to 1315 location Keller 441323 (Max Rm. capacity 700) " 
                   + "(Instr: W jackson)");

    assertEquals("Checking splitup and getLocation", tlp.getTime(), "1200 pm-115 pm");
  }
  /**
   * Test the get split function and getDay.
   * 
   */
  @Test
  public void testGetDay() {

    assertEquals("Checking splitup and getDay()", tlp.getDay(), "MW");
    
    
    tlp.setRawString("MWTF 1200 to 1315 location Keller 441323 (Max Rm. capacity 700) " 
                   + "(Instr: W jackson)");
 
    assertEquals("Checking splitup and getLocation", tlp.getDay(), "MWTF");
  }

}
